home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1707 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.0 KB  |  35 lines

  1. Path: ix.netcom.com!netnews
  2. From: n4jvp@ix.netcom.com (n4jvp)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Fishing for Opinions:  Global Variables in GUI
  5. Date: Fri, 12 Jan 1996 12:59:08 GMT
  6. Organization: Netcom
  7. Message-ID: <30f657d7.2731554@ixnews1.ix.netcom.com>
  8. References: <4cjg9c$m92@crchh327.rich.bnr.ca> <4d3o7o$d9m@news.bridge.net>
  9. NNTP-Posting-Host: ix-nas-nh1-17.ix.netcom.com
  10. X-NETCOM-Date: Fri Jan 12  5:01:06 AM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13.     To avoid using globals in multi-module programs I have been
  14. using the extern keyword within the specific functions needing access
  15. to the globals i.e.
  16.  
  17. void foo()
  18. {
  19.     ....
  20. }
  21.  
  22. int bar(int num)
  23. {
  24.     extern Square * Sfirst;
  25.     ....
  26. }
  27.  
  28. I find that in addition to making the code easier to follow, if I wish
  29. to move bar() from one module to another I don't have to worry if the
  30. Square * is global to that module. I suppose I could pass the pointer
  31. as an argument but some of the functions that call bar() do not have
  32. scope access to the Square *. 
  33.  
  34. Is this a good practice or is there a better way to do it? 
  35.